/*
 * BinaryGeneticAlgorithm.h
 *
 *  Created on: Oct 17, 2013
 *      Author: filipe
 */

#ifndef BINARYGENETICALGORITHM_H_
#define BINARYGENETICALGORITHM_H_

#include <cstdlib>
#include "OptimizationAlgorithm.h"
#include "BinaryGeneticAlgorithmParameters.h"

class BinaryGeneticAlgorithm: public OptimizationAlgorithm<unsigned int>
{
	double *_current_estimate;
	double *_individual_estimate; // Memory block used in intermediary process to avoid allocation's
	double *_fitness_per_individual;

	protected:
		BinaryGeneticAlgorithmParameters *_parameters;
		// **************************************************************************
		// TODO: criar uma classe abstrata para os parametros desplugada dessa classe
		// **************************************************************************
		double (*_fitness_function)(double *data);
		void _UpdateCurrentEstimate(void);
		void _UpdateFitness();
		int _GetIndividualWithMaximumFitness(void) const;
		double *_CalculateEstimateOfIndividual(int individual) const;
		void _GenerateNewIndividuals();
	public:
		BinaryGeneticAlgorithm(BinaryGeneticAlgorithmParameters *parameters = NULL, double (*fitness_function)(double *data) = NULL);
		~BinaryGeneticAlgorithm();

		virtual void Optimize();
		virtual double* GetCurrentEstimate();
};

#endif /* BINARYGENETICALGORITHM_H_ */
